package com.link.server.ws.handle.impl;

import com.link.common.packet.RequestOperate;
import com.link.common.packet.ResponseOperate;
import com.link.common.packet.resp.SimplePacketResp;
import com.link.common.util.BinaryUtils;
import com.link.server.ws.handle.HandleComponent;
import com.link.server.ws.handle.Handler;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

@HandleComponent(RequestOperate.SEND_VERIFICATION_CODE)
public class SendVerificationCodeHandle implements Handler {
    private static final Logger logger = LoggerFactory.getLogger(SendVerificationCodeHandle.class);

    @Override
    public   void invoke(RequestOperate operate, ByteBuf packet, ChannelHandlerContext ctx) throws  Exception{

        var mobile= BinaryUtils.readString(packet);
        String verificationCode = String.format("%06d", new Random().nextInt(999999));

//ctx.channel().attr(Handler.VERIFICATION_CODE_KEY).set(verificationCode);
        ctx.channel().attr(Handler.VERIFICATION_CODE_KEY).set("123456");

logger.info("给手机：{}发送验证码：{}",mobile, verificationCode);

        this.send(ctx,SimplePacketResp.response(ctx,ResponseOperate.SEND_VERIFICATION_CODE,(short) 200));

    }
}
